package com.fpx.open.platform.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.fpx.open.platform.common.constant.BaseErrorCodeConstant;
import com.fpx.open.platform.dao.mapper3.RoleMapper;
import com.fpx.open.platform.domain.ApplicationCustomer;
import com.fpx.open.platform.domain.TokenRole;
import com.fpx.open.platform.domain.exception.ServiceException;
import com.fpx.open.platform.service.BaseService;

//@Service
public class BaseServiceImpl implements BaseService{

    @Resource
    private RoleMapper roleMapper;
    
    @Override
    public TokenRole verifyToken(String token,Integer appId) throws ServiceException {
        
        TokenRole tokenRole = roleMapper.selectToken(token);
        if(tokenRole == null){
            throw new ServiceException("非法的TOKEN.",BaseErrorCodeConstant.B001);
        }
        ApplicationCustomer applicationCustomer = new ApplicationCustomer();
        applicationCustomer.setId(appId);
        applicationCustomer.setTokenId(tokenRole.getTokenId());
        ApplicationCustomer tempApplicationCustomer = roleMapper.selectApplicationCustomer(applicationCustomer);
        if(null == tempApplicationCustomer){
            throw new ServiceException("TOKEN没有授权",BaseErrorCodeConstant.B002);
        }
        return tokenRole;
    }

}
